package csdn;

//实现Runnable接口
class MyRunnable implements Runnable{
    @Override
    public void run() {
        //描述了线程要完成的逻辑
        for (int i = 0; i < 3; i++) {
            System.out.println("hello Thread");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
public class D2 {
    public static void main(String[] args) throws InterruptedException {
        MyRunnable runnable = new MyRunnable();
        //线程要执行的任务通过Runnable描述
        Thread t = new Thread(runnable);
        t.start();
        for (int i = 0; i < 3; i++) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }
}
